package com.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import com.model.auto.PreferenceDescription;
import com.service.IPreferenceDescriptionService;
import com.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author astupidcoder
 * @since 2022-09-14
 */
@RestController
@RequestMapping("/preferenceDescription")
public class PreferenceDescriptionController{
    @Autowired
    private IPreferenceDescriptionService preferenceDescriptionService;

    @GetMapping("/getPreferenceDescription")
    public R getPreferenceDescription(String stuId) {
        PreferenceDescription preferenceChoice = preferenceDescriptionService.getOne(new LambdaQueryWrapper<PreferenceDescription>()
                .eq(PreferenceDescription::getStuId, stuId));
        return R.ok(preferenceChoice);
    }

    @PostMapping("SaveOrUpdatePreferenceDescription")
    public R SaveOrUpdatePreferenceDescription(@RequestBody PreferenceDescription preferenceDescription) {
        boolean result = preferenceDescriptionService.saveOrUpdate(preferenceDescription);
        if (!result) {
            return R.error();
        }
        return R.ok();
    }
}
